package com.qf.controller;

import com.qf.dto.PageSearchDTO;
import com.qf.entity.MallGoodsBrand;
import com.qf.mapper.GoodsBrandMapper;
import com.qf.service.IGoodsBrandService;
import com.qf.vo.PageResult;
import com.qf.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>title: com.qf.controller</p>
 * <p>Company: wendao</p>
 * author zhuximing
 * date 2021/9/15
 * description:
 */
@RestController
@RequestMapping("brand")
@CrossOrigin
@Api(tags="品牌管理接口")
public class GoodsBrandController {

    @Autowired
    private IGoodsBrandService goodsBrandService;

    @Autowired
    private GoodsBrandMapper goodsBrandMapper;
    @PostMapping("page")
   // @PreAuthorize("hasAnyRole('xx')")
    @ApiOperation("品牌分页及条件查询")
    public PageResult<MallGoodsBrand> page(@RequestBody @ApiParam("条件及分页信息参数") PageSearchDTO<MallGoodsBrand> pageSearchDTO){

        return  goodsBrandService.selectByPage(pageSearchDTO);

    }

    @RequestMapping("save")
    public Result save(@RequestBody MallGoodsBrand brand){

        return  goodsBrandService.save(brand);
    }
    @RequestMapping("update")
    public Result update(@RequestBody MallGoodsBrand brand1){

        return  goodsBrandService.update(brand1);
    }
    @RequestMapping("deleteOne")
    public Result delete(@RequestBody MallGoodsBrand brand){
        long id = brand.getId();
        return  goodsBrandService.delete(id);
    }
    @RequestMapping("deleteList")
    public Result deleteList(@RequestBody List<MallGoodsBrand> brandList){
//        List<Result> deleteList = new ArrayList<>();
//        for (MallGoodsBrand mallGoodsBrand : brandList) {
//            Long id = mallGoodsBrand.getId();
//            Result delete = goodsBrandService.delete(id);
//            deleteList.add(delete);
//        }

            return goodsBrandService.deleteList(brandList);

//        return new Result(deleteList != null?true:false, deleteList!=null?"success":"fail");
    }
    @RequestMapping("all")
    public List<MallGoodsBrand> all(){
//    @PreAuthorize("hasAnyRole('ROLE_PRODUCT','ROLE_ADMIN')")
        //@PreAuthorize("hasAnyAuthority('copy111111')")
        return goodsBrandMapper.findAll();
    }


}